package elems;

import common.ParseException;
import common.Strings;

import java.util.ArrayList;

public class Comment extends ClassElem{
    private String comment;

    private Comment(String comment) {
        super(null);
        this.comment = comment;
    }

    public void print(int shift) {
        System.out.println(Strings.getSpaceShift(shift) + "/* COMMENT "+comment+" */");
    }

    public static boolean is(int lineNum, String text) throws ParseException {
        ArrayList<String> strs=Strings.split(lineNum,text,"//",true,false);
        return strs.get(0).trim().length() == 0 && strs.size() > 1 && strs.get(1).trim().length() > 0;
    }

    public static Comment get(int lineNum, String text) throws ParseException {
        if(!is(lineNum,text))
            return null;
        return new Comment(Strings.split(lineNum,text,"//",true,false).get(1).trim());
    }
}
